<?php

class Crud_Db_Table extends Crud_Db_Table_Abstract
{
	/**
	 * Return table class by table name.
	 * 
	 * @param mixed $table
	 * @return Zend_Db_Table_Abstract
	 */
	protected function _getTable($table)
	{
		if (substr($table, -4) == 'Peer') {
			$peerName = $table;
		} else {
			$filter = new Zend_Filter_Word_UnderscoreToCamelCase();
			$peerName = $filter->filter($table);
			$peerName .= 'Peer';
		}
		
		$callback = array($peerName, 'getInstance');
		if (!is_callable($callback)) {
			throw new Crud_Exception("Cant create wrapper by given table name: `$table`");
		}
		
		$peer = call_user_func($callback);
		return $peer;
	}
}